package com.cloudcc.mobile.view.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.view.base.BaseActivity;

public class NewContactDetails extends BaseActivity {
    private ImageView bianji, shanchu, returnimage, user_follow, newcontact_item_name_image;
    private TextView textView_name_chuangjian, textview_name_kehu, tv_name, tv_creatTime, tv_juese;
    private String name, id, creatName, creatId, creatTime, kehu_name, kehu_id, juese, lianxiren_name, lianxirenjuese_id, isdefault, lianxiren_id, jueseid,accountpermiss;
    private String recordId, layoutId, relatedlistId;
    private boolean shanchuB = true;
    private boolean bianjiB = true;
    public  static NewContactDetails instance = null;
    private RelativeLayout topLayoutBackg;
    private TextView toastHintContent;
    private ImageView imgDelete11s;
    FrameLayout layoutTop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_contact_details);
        instance = this;
        initView();
        addlistener();
        initdata();
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_new_contact_details;
    }
    private void initdata() {
        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        creatName = intent.getStringExtra("creatname");
        creatId = intent.getStringExtra("creatid");
        creatTime = intent.getStringExtra("creattime");
        kehu_name = intent.getStringExtra("kehuname");
        kehu_id = intent.getStringExtra("kehuid");
        juese = intent.getStringExtra("juese");
        lianxiren_name = intent.getStringExtra("lianxirenname");
        lianxirenjuese_id = intent.getStringExtra("lianxirenjueseid");
        isdefault = intent.getStringExtra("isdefault");
        id = intent.getStringExtra("id");
        recordId = intent.getStringExtra("recordId");
        layoutId = intent.getStringExtra("layoutId");
        relatedlistId = intent.getStringExtra("relatedlistId");
        lianxiren_id = intent.getStringExtra("lianxirenid");
        jueseid = intent.getStringExtra("jueseid");
        accountpermiss = intent.getStringExtra("accountpermiss");
        tv_name.setText(name);

        tv_creatTime.setText(","+getFormatTime(creatTime));
        tv_juese.setText(juese);
        textView_name_chuangjian.setText(creatName);
        textview_name_kehu.setText(kehu_name);
        if ("1".equals(isdefault)) {
            newcontact_item_name_image.setVisibility(View.VISIBLE);
        } else {
            newcontact_item_name_image.setVisibility(View.GONE);
        }
//        String userId = UserManager.getManager().getUser().userId;
//        String url = UrlTools.getTopImage(userId);
        //没有图片 所以全部使用默认的头像
        Drawable defaultDrawable = getResources().getDrawable(R.drawable.man_man);
        user_follow.setImageDrawable(defaultDrawable);
//        UserUtils.setLogoRound_z(url, user_follow,
//                UserUtils.getBackGroudColorByUserIdHash(userId, NewContactDetails.this),
//                UserUtils.getNickRowName(name), NewContactDetails.this);
    }


    //判断时间格式
    public String getFormatTime(String time) {
        String Hour;
        String year = time.substring(0, 10) + " ";//YYYY-MM-Dd
        String shi = time.substring(10, time.length() - 6).toString().trim();
        String minute = time.substring(14, time.length() - 3);
        int data = Integer.valueOf(shi) - 12;
        if (data > 0) {
            Hour = year + "下午 " + String.valueOf(data) + ":" + minute;
        } else {
            Hour = year + "上午 " + shi + ":" + minute;
        }

        return Hour;
    }


    private void addlistener() {
        imgDelete11s.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                layoutTop.setVisibility(View.GONE);
            }
        });
        bianji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bianji.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_edit_pressed));
                Intent intent = new Intent(NewContactDetails.this, NewContactEdit.class);
                intent.putExtra("kehuname", kehu_name);
                intent.putExtra("kehuid", kehu_id);
                intent.putExtra("lianxirenname", lianxiren_name);
                intent.putExtra("lianxirenid", lianxiren_id);
                intent.putExtra("juese", juese);
                intent.putExtra("jueseid", jueseid);
                intent.putExtra("isdefault", isdefault);
                intent.putExtra("recordId", recordId);
                intent.putExtra("layoutId", layoutId);
                intent.putExtra("relatedlistId", relatedlistId);
                intent.putExtra("id", id);
                startActivity(intent);
            }
        });
        shanchu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shanchu.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_delete_pressed));
                Intent intent = new Intent(NewContactDetails.this, NewcontactDelete.class);
                intent.putExtra("id", id);
                intent.putExtra("recordId", recordId);
                intent.putExtra("layoutId", layoutId);
                intent.putExtra("relatedlistId", relatedlistId);
                intent.putExtra("lianxirenname", lianxiren_name);
                startActivity(intent);
            }
        });
        returnimage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                returnimage.setImageDrawable(getResources().getDrawable(R.drawable.fujin_back));
                finish();
            }
        });
        textView_name_chuangjian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent Intent = new Intent(NewContactDetails.this, NewUserInfoActivity.class);
                Intent.putExtra("userId",creatId);
                startActivity(Intent);
            }
        });
        textview_name_kehu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if("1".equals(accountpermiss)){
                    Intent Intent = new Intent(NewContactDetails.this, BeauInfoActivity.class);
                    Intent.putExtra("web", kehu_id);
                    Intent.putExtra("beau.nameid", "account");
                    startActivity(Intent);
//                }else{
//                    topLayoutBackg.setBackground(getResources().getDrawable(R.drawable.toast_hint_red));
//                    toastHintContent.setText(R.string.contactquanxian);
//                    topLayoutBackg.setVisibility(View.GONE);
//                    layoutTop.setVisibility(View.VISIBLE);
//                    new AnimViewUtils().appearToast(topLayoutBackg);
//                }

            }
        });
    }

    private void initView() {
        newcontact_item_name_image = (ImageView) findViewById(R.id.newcontact_item_name_image);
        bianji = (ImageView) findViewById(R.id.newcontact_bianji);
        shanchu = (ImageView) findViewById(R.id.newcontact_shanchu);
        returnimage = (ImageView) findViewById(R.id.ContactDetails_return);
        textView_name_chuangjian = (TextView) findViewById(R.id.ContactDetails_chuangjian_name);
        textview_name_kehu = (TextView) findViewById(R.id.ContactDetails_kehu_value);
        user_follow = (ImageView) findViewById(R.id.user_follow);
        tv_name = (TextView) findViewById(R.id.user_name);
        tv_creatTime = (TextView) findViewById(R.id.ContactDetails_chuangjian_shijian);
        tv_juese = (TextView) findViewById(R.id.ContactDetails_juese_value);

        toastHintContent = (TextView) findViewById(R.id.toastHintContent);
        imgDelete11s = (ImageView) findViewById(R.id.imgDeletes);
        topLayoutBackg = (RelativeLayout) findViewById(R.id.topLayoutBackg);
        layoutTop = (FrameLayout) findViewById(R.id.layoutTop);

        bianji.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_edit_default));
        shanchu.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_delete_default));
        returnimage.setImageDrawable(getResources().getDrawable(R.drawable.fujin_back));
    }

    @Override
    protected void onResume() {
        super.onResume();
        bianji.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_edit_default));
        shanchu.setImageDrawable(getResources().getDrawable(R.drawable.contactpersonrole_delete_default));
        returnimage.setImageDrawable(getResources().getDrawable(R.drawable.fujin_back));
    }
}
